package com.game.league.mine.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

import com.game.base.app.base.BaseAdapter;
import com.game.base.glideV4.ImageLoader;
import com.game.league.R;
import com.game.league.articles.exchange.Exchange;
import com.game.league.articles.table.Articles;
import com.game.league.databinding.AdapterMineCollectionBinding;

/**
 * 我兑换的物品
 * Created by Su on 2019/5/22.
 */
public class CollectionAdapter extends BaseAdapter<Exchange, AdapterMineCollectionBinding> {

    public CollectionAdapter(Activity activity) {
        super(activity);
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.adapter_mine_collection;
    }

    @Override
    protected void onBindItem(AdapterMineCollectionBinding binding, Exchange item, int position) {
        Articles articles = item.getArticles();
        ImageLoader.loadRoundCenterCrop(mActivity, articles.getImgUrl(), binding.ivImage);
        binding.tvNum.setText(String.valueOf(item.getNum()));

        String title = item.getStatusText() + articles.getTitle();
        SpannableStringBuilder builder = new SpannableStringBuilder(title);
        if (item.getStatus() == 1) {
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        binding.tvText.setText(builder);
    }
}
